package redis

import (
	"FeedXmh/app/model"
	"fmt"
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/text/gstr"
	"github.com/gogf/gf/util/gconv"
)

func QuerySn(sn string) (addr string) {
	val, err := g.Redis("default").Do("keys", fmt.Sprintf("%s:device:%s:*:node:%s:*", model.Redis_Node_Prefix, model.GW_MODE, sn))
	if err != nil {
		g.Log().Line(true).Error(err)
	} else {
		if val != nil {
			//g.Log().Line(true).Debug(val)
			var vals []interface{}
			vals = val.([]interface{})
			for _, v := range vals {
				g.Log().Line(true).Debug(gconv.String(v))
			}
			if len(vals) > 0 {
				v := gconv.String(vals[0])
				v_arr := gstr.Split(v, ":")
				if len(v_arr) >= 7 {
					addr = v_arr[3]
					g.Log().Line(true).Debugf("addr=%s", addr)
				}

			}
		}
	}

	return addr
}
